package com.yc.thread.lock8;

import java.util.concurrent.TimeUnit;

/**
 * 8锁，关于锁的8个问题
 *
 */
public class TestLock1 {
    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();

        new Thread(() -> {
           phone.sendMsg();
        }, "sendMsg").start();

        TimeUnit.SECONDS.sleep(1L);

        new Thread(() -> {
            phone.call();
        }, "call").start();
    }


}
class Phone{

    
    // synchronized 锁的对象时方法的调用者
    // 两个方法用的是同一个锁，谁先拿到谁先执行
    public synchronized void sendMsg() {
        System.out.println("sendMsg");
    }

    public synchronized void call() {
        System.out.println("call");
    }
}